<?php

namespace App\Http\Controllers\Managea;

use App\Traits\BaseFun;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repositories\UserslogRepository;
use App\Repositories\UsersRepository;

class UsersLogController extends Controller
{
    public function __construct(
        UsersLogRepository $UsersLogRepository,
        UsersRepository $UsersRepository

    ) {
        $this->UsersLogRepository = $UsersLogRepository;
        $this->UsersRepository = $UsersRepository;
    }

    public function userLog(Request $request)
    {
        $where = [];
        if ($request->order_sn) {
            $where['order_sn'] = $request->order_sn;
        }
        if ($request->type) {
            $where['type'] = $request->type;
        }
        $where['userid']=$request->userid;
        $userLog['list'] = $this->UsersLogRepository->pageList($where);
        $userLog['chongzhi']=$this->UsersLogRepository->logCount(['type'=>1,'userid'=>$request->userid]);
        $userLog['xiaofei']=$this->UsersLogRepository->logCount(['type'=>2,'userid'=>$request->userid]);
        $userLog['tuikuan']=$this->UsersLogRepository->logCount(['type'=>3,'userid'=>$request->userid]);
        if ($userLog) {
            $ArrDate = ['state' => 0, 'data' => $userLog, 'token' => $request->input('token')];
        } else {
            $ArrDate = ['state' => 2, 'data' => '', 'msg' => '获取失败!'];
        }

        return BaseFun::jsonReturn($ArrDate);
    }

    public function RechargeLog(Request $request)
    {
         $where=[];
         if ($request->start_time && $request->end_time) {
            $where['start_time']=$request->start_time.' 00:00:01';
            $where['end_time']=$request->end_time.' 00:00:01';
        }
        $RechargeLog = $this->UsersLogRepository->LogList($where);
        foreach ($RechargeLog as $key => $value) {
            $RechargeLog[$key]['username']=$this->UsersRepository->info(['id'=>$value['userid']])['nickname'];
        }
       
        if ($RechargeLog) {
            $ArrDate = ['state' => 0, 'data' => $RechargeLog, 'token' => $request->input('token')];
        } else {
            $ArrDate = ['state' => 2, 'data' => '', 'msg' => '获取失败!'];
        }

        return BaseFun::jsonReturn($ArrDate);
    }


}
